package com.fulin.jdk8.stream;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
*
* @description 
* @auther fulin16@crnet.com.hk
* @since 2019年2月21日 下午1:52:44
*
*/
public class Client {
	public static void main(String[] args) {
		testBenfude();
	}
	
	private static void testBenfude(){
		Map<Integer, Long> result = Arrays.asList(130.62,428.07,40.40,201.51,300.23,136.31,173.65,669.69,76.00,156.04,28.80,161.42,85.93,296.13,320.80,194.00,414.20,159.40,98.53,132.70,66.24,217.80,108.82,45.80,120.75,414.99,316.06,200.60,516.00,62.70,155.90,152.68,45.00,210.49,43.59,283.85,288.79,98.93,475.40,317.38,10.50,153.10,35.60,183.50,216.61,239.82,82.75,46.12,18.00,433.87,126.56,228.70,350.86,40.90,454.98,80.89,113.93,78.00,46.66,200.39,13.20,91.50,80.29,138.70,136.00,59.48,187.70,382.79,54.80,64.59,108.80,39.20,29.60,60.90,50.10,88.20,12.80,100.60,261.60,474.54,223.40,88.70,29.80,209.60,65.66,62.20,98.00,84.20,67.70,124.31,348.80,98.50,282.21,358.20,53.70,55.90,18.00,63.90,297.78,34.40,362.34,17.60,30.75,47.78,21.86,72.30,29.70,137.44,154.07,50.28,163.43,104.70,104.62,29.28,71.70,65.27,10.50,68.50,164.04,76.04,265.00,374.34,14.30,217.46,56.80,300.66,45.44,28.20,47.40,29.80,27.20,171.60,114.73,36.60,127.49,6.50,71.60,76.67,192.13,283.31,36.80,84.36,62.51,42.20,449.70,16.90,190.90,25.70,149.19,457.74,251.62,91.40,58.70,24.70,375.31,126.03,115.50,38.50,76.00,84.40,203.10,133.30,60.47,92.90,580.70,55.20,128.93,133.58,96.44,75.50,109.40,167.09,38.00,70.80,492.11,37.20,23.70,175.00,53.29,181.96,869.10,95.50,190.27,444.80,124.35,47.04,20.30,186.02,219.39,101.78,15.60,270.23,61.70,258.20,265.70,7.90,20.49,257.41,35.80,153.27,36.20,97.31,158.20,82.00,280.12,79.60,190.90,108.51,195.27,223.07,1355.73,133.78,496.20,51.30,75.80,399.00,25.00,147.76,49.34,330.90,117.93,184.98,273.39,79.12,138.86,181.33,12.00,189.42,63.10,554.90,94.25,226.90,237.80,242.37,262.01,98.05,167.74,366.30,58.18,68.30,314.70,793.44,17.80,10.07,176.90,180.51,268.88,40.70,105.20,309.06,107.37,129.30,62.29,17.40,359.43,125.74,209.86,53.87,380.68,62.10,77.75,42.20,415.79,249.53,474.68,93.66,88.41,205.56,116.30,11.50,238.45,115.80,237.06,646.04,37.23,107.47,248.80,90.60,39.90,48.50,69.29,109.40,63.80,144.42,23.80,324.48,126.50,31.60,95.67,470.58,74.35,176.60,16.30,22.30,129.10,12.80,149.90,145.34,134.10,27.30,146.38,9.90,31.14,32.10,228.54,39.30,312.59,263.62,110.64,108.81,16.90,280.17,194.98,214.50,236.20,24.00,51.90,190.40,37.40,35.90,70.82,113.38,89.08,71.87,110.88,39.20,312.23,77.90,48.30,387.18,315.69,72.09,11.95,400.05,73.25,164.40,234.06,12.80,33.30,77.76,196.22,19.30,320.86,481.61,83.00,853.37,297.76,818.69,57.30,71.62,41.40,317.34,174.03,270.07,75.75,128.85,154.80,512.75,321.43,92.79,335.57,50.50,21.40,65.50,287.88,139.00,108.15,545.40,51.56,86.20,156.20,23.90,108.30,26.80,798.10,297.39,45.20,355.02,143.73,27.60,490.90,110.93,281.70,26.10,223.40,16.80,81.80,36.69,202.32,343.46,107.58,122.20,242.90,65.30,28.69,1659.08,266.90,272.34,155.78,36.70,318.98,158.20,48.70,212.04,54.73,528.46,173.61,49.10,122.11,65.26,76.72,131.11,95.50,288.29,67.40,33.39,342.37,111.60,85.92,92.69,152.20,65.50,35.00,245.88,322.00,162.96,68.80,119.84,258.00,538.73,61.50,96.70,114.38,106.67,73.40,793.65,99.20,182.79,210.35,68.90,98.96,120.68,49.10,70.29,134.42,40.50,44.70,90.93,30.10,77.80,260.50,52.50,115.50,187.48,570.20,280.55,91.06,366.45,52.31,28.70,59.20,136.64,217.04,220.07,17.30,55.34,28.86,291.34,83.70,77.95,62.30,49.50,306.00,223.81,86.38,66.14,102.54,189.60,42.45,263.14,85.50,202.72,58.85,188.12,16.40,96.30,36.80,28.49,169.96,66.18,39.20,232.40,60.17,643.50,90.21,253.40,172.40,30.24,46.97,268.76,106.84,347.00,73.40,80.50,34.51,180.83,21.40,90.90,443.20,115.28,37.60,64.24,48.10,305.11,215.76,77.62,90.73,33.80,26.60,552.45,122.04,104.10,211.30,44.37,90.05,258.00,194.52,134.00,93.30,58.71,67.70,225.86,92.80,124.24,140.10,179.40,151.63,43.08,103.24,86.69,7.50,42.41,190.80,147.63,373.40,121.20,214.70,374.30,87.20,35.00,233.07,534.50,94.90,30.40,44.81,127.09,43.17,55.90,33.60,353.15,324.00,149.40,55.80,83.90,20.74,103.80,213.20,396.71,120.01,59.16,232.35,306.00,411.83,32.20,76.30,108.00,247.80,304.55,310.50,243.92,39.53,43.60,399.49,153.90,413.10,11.40,38.50,302.40,356.33,78.40,82.63,136.21,224.70,98.50,204.93,1427.00,110.10,74.87,58.40,18.00,80.40,179.80,332.10,164.29,113.57,294.60,85.66,119.15,466.08,452.94,432.50,142.00,22.51,51.40,155.83,258.06,133.40,73.92,25.10,102.50,44.84,180.20,112.48,123.20,12.04,381.70,585.79,83.29,202.20,164.84,73.80,140.18,99.77,358.67,39.99,99.17,238.60,386.57,100.60,67.30,323.20,210.70,74.00,170.80,194.10,116.96,233.40,169.07,398.00,117.58,211.41,45.19,221.55,196.13,335.24,100.66,232.90,56.32,268.20,276.69,101.63,44.50,26.90,415.40,382.53,142.10,180.67,326.40,134.05,148.48,18.00,154.71,70.80,183.35,23.40,266.28,52.80,90.56,139.54,22.60,192.76,205.40,150.96,74.70,143.60,212.20,86.99,121.60,304.70,134.70,235.30,62.60,295.10,209.56,33.61,50.00,234.96,234.60,60.50,176.99,29.91,113.40,139.60,117.45,188.50,222.50,284.14,99.49,23.30,391.77,229.62,98.50,220.28,46.48,77.40,369.21,57.60,236.07,44.50,110.48,7.50,171.30,45.33,367.59,119.94,13.50,74.31,99.95,87.90,100.30,119.40,49.32,379.00,76.40,47.50,80.70,83.11,226.90,37.49,47.16,463.10,767.38,46.00,54.67,54.12,113.13,38.46,179.16,175.57,91.64,124.13,343.98,76.10,147.39,65.18,505.34,294.02,311.45,143.49,180.78,61.00,1327.70,195.95,187.22,74.05,109.96,112.61,60.06,43.00,87.38,131.10,164.10,245.35,183.61,229.00,12.80,80.50,197.75,197.74,39.51,20.70,495.46,147.30,161.39,31.20,214.70,165.13,156.50,117.84,477.70,125.90,192.70,82.20,254.80,34.81,281.91,622.58,59.00,153.60,86.50,232.04,102.80,200.70,113.60,219.62,106.21,1387.90,139.60,260.20,90.50,102.40,409.70,258.00,29.24,51.10,659.70,60.50,30.00,235.78,158.01,199.06,281.30,174.50,332.70,94.30,56.10,216.10,229.90,109.89,113.47,36.00,146.40,225.55,106.85,213.37,207.90,137.70,374.86,164.94,45.19,124.00,415.70,90.20,287.01,98.48,258.89,136.57,163.90,68.80,355.73,57.60,98.79,61.80,226.90,70.38,188.43,288.52,173.45,99.32,29.86,50.90,49.60,59.06,38.20,52.70,21.40,79.50,452.14,53.80,464.10,69.60,174.44,44.70,198.20,294.59,346.79,463.90,63.00,20.10,120.50,156.10,263.79,42.90,134.00,784.59,122.00,236.35,22.10,190.40,54.37,39.00,50.90,22.34,78.49,364.19,172.80,24.80,51.62,169.27,140.40,124.09,28.60,57.50,176.68,156.10,135.65,63.20,120.50,53.70,24.00,23.45,112.15,134.75,130.10,166.42,101.20,828.43,200.72,168.95,153.11,197.64,31.90,58.85,61.80,95.78,512.86,13.00,290.85,191.98,316.00,93.09,195.98,56.70,62.00,205.80,128.06,213.60,49.82,141.30,346.49,436.60,169.73,38.93,162.81,128.11,229.98,208.89,95.70,31.60,261.60,300.80,213.30,44.14,287.00,265.37,133.02,92.80,167.56,52.53,151.31,90.29,71.06,83.46,34.80,288.60,114.30,190.06,114.94,130.86,103.72,89.36,160.30,93.63,675.69,229.41,127.80,10.50,166.80,54.60,68.73,333.38,193.26,352.30,164.75,59.10,89.30,116.04,202.00,2430.30,31.02,102.71,190.10,12.00,145.82,86.88,13.40,65.94,272.55,206.24,49.60,123.94,16.70,66.35,146.00,31.80,91.49,160.01,225.45,107.19,14.80,7.90,368.07,372.97,183.60,29.30,112.64,306.70,268.45,320.56,27.80,60.70,59.91,95.10,1357.50,89.30,247.83,78.00,216.67,104.42,54.40,316.94,50.19,190.87,12.80,441.06,76.37,213.90,91.00,35.20,189.02,68.50,76.59,13.20,37.21,32.39,25.00,113.07,17.10,38.80,30.70,159.90,42.40,51.86,187.18,105.98,537.59,12.80,83.60,234.40,100.40,80.54,127.35,343.04,97.50,110.40,78.88,240.61,164.88,18.00,151.06,78.86,99.76,51.30,378.20,239.70,181.37,786.29,84.77,182.90,116.20,14.82,77.89,19.00,165.45,210.30,16.30,190.65,89.10,16.90,162.90,251.63,133.78,21.80,232.90,353.12,56.30,52.20,18.00,84.70,236.56,33.10,30.09,243.04,1315.80,25.00,209.70,88.26,114.00,204.14,55.30,176.50,306.00,132.80,35.20,199.80,42.48,51.30,178.81,17.08,96.90,115.45,59.36,205.60,153.86,109.62,399.70,34.37,252.40,173.94,636.79,76.90,23.50,49.60,79.40,80.10,107.50,963.10,18.70,58.80,87.50,73.00,25.41,114.69,124.23,15.10,51.57,59.30,31.60,100.47,99.80,166.25,84.14,59.40,21.60,49.92,418.67,27.40,53.19,183.66,110.30,50.22,99.60,79.87,43.00,149.30,219.30,48.50,257.02,33.40,385.34,126.06,120.99,279.75,50.50,702.70,122.30,167.74,59.69,71.91,303.00,11.68,226.40,24.80,152.03,153.44,159.00,12.00,116.85,714.80,64.30,99.52,33.70,76.62,143.24,22.80,109.66,10.90,242.10,66.70,12.80,155.77,110.81,367.51,27.60,79.40,33.60,9.90,60.90,32.40,233.70,24.62,33.80,46.05,20.00,26.90,45.50,12.80,14.80,43.83,25.80,25.60,133.60,93.84,33.50,48.00,84.90,16.00,235.27,175.66,64.00,66.80,46.30,760.34,12.80,675.90,126.41,48.85,606.70,233.10,42.55,9.90,80.70,64.70,15.40,193.32,34.20,154.03,84.08,26.00,158.84,70.43,45.62,233.50,250.53,29.60,10.50,399.57,68.50,390.56,12.80,50.80,72.89,11.72,56.52,41.89,27.12,92.13,15.00,44.80,16.82,53.60,12.80,63.30,30.00,38.42,14.00,44.50,58.80,12.80,108.87,86.49,61.50,59.10,47.75,82.95,69.50,320.57,87.30,25.30,46.00,90.47,72.87,21.37,18.00,263.71,26.76,117.00,39.60,20.60,14.29,111.93,439.50,54.00,176.14,496.27,254.10,30.60,465.30,65.13,48.67,388.00,571.00,77.62,31.00,32.49,115.00,36.84,7.90,124.88,40.10,387.44,101.91,838.10,165.27,80.09,27.70,66.09,63.96,203.14,12.80,60.60,297.88,156.37,32.00,111.11,289.49,72.00,51.50,119.81,479.22,70.20,29.23,166.36,25.80,388.00,398.00,89.59,72.42,241.10,23.32,63.79,137.30,87.21,437.37,204.78,309.07,295.43,254.42,252.45,104.16,134.86,25.40,71.10,60.38,133.80,234.08,88.33,452.60,138.18,101.20,140.03,38.20,269.36,313.28,120.17,178.60,45.55,22.50,93.90,82.67,172.88,111.30,98.47,38.19,110.88,50.21,33.80,242.80,324.90,36.35,172.60,26.14,128.00,244.46,111.50,107.20,181.40,20.20,160.50,33.00,34.00,259.18,151.10,23.10,124.24,417.13,98.10,323.07,365.80,240.51,55.50,36.00,47.60,12.80,214.50,386.37,215.10,174.07,23.93,75.38,43.43,279.20,131.43,53.60,18.80,49.90,40.10,68.16,110.43,112.40,58.40,123.05,218.28,328.10,359.80,100.57,54.60,486.19,38.69,12.90,100.15,10.50,28.00,99.00,64.00,31.39,36.70,46.50,35.10,105.40,170.75,29.12,53.17,65.60,43.00,53.00,131.30,145.50,67.97,239.05,359.50,18.00,297.22,33.50,168.06,115.53,205.95,85.50,207.90,52.24,188.80,94.60,82.60,141.03,119.10,592.20,46.10,88.29,210.52,68.75,191.68,65.00,23.40,48.27,245.61,91.14,23.10,85.49,5.92,109.39,1315.80,281.87,878.70,105.10,146.95,178.30,31.39,132.40,708.40,45.60,52.70,1110.40,84.44,348.87,98.33,170.00,40.30,39.30,28.30,62.84,343.38,40.80,132.92,316.41,260.79,34.20,112.60,18.40,278.47,56.36,254.63,100.30,1509.73,10.90,54.30,70.19,49.00,95.10,53.40,95.13,30.48,727.52,556.13,232.13,498.74,33.81,107.70,59.59,12.80,231.13,104.98,16.90,128.81,77.90,121.49,44.93,97.05,25.72,142.47,42.55,37.00,131.30,494.40,676.26,84.74,196.73,212.13,165.18,123.12,16.82,23.30,257.70,50.64,102.86,88.50,43.60,110.60,366.95,47.10,57.60,41.70,83.80,92.65,46.60,65.14,20.40,55.40,31.60,91.30,563.48,212.17,416.62,137.05,205.69,140.40,88.80,110.30,43.60,204.21,241.00,53.07,52.72,83.40,24.40,66.00,95.00,331.65,409.28,126.10,128.98,198.54,185.11,40.05,103.30,70.40,37.40,35.80,84.71,73.43,84.87,26.85,60.30,57.30,102.31,231.00,22.60,80.63,63.99,74.30,96.11,38.72,29.22,155.12,231.33,23.70,507.17,1380.30,80.70,182.66,73.80,24.20,40.49,69.80,19.60,330.51,99.70,90.87,306.54,13.40,18.00,15.60,41.70,103.91,44.22,71.06,97.27,19.70,123.03,42.50,218.97,54.20,444.30,68.20,92.49,195.24,98.20,92.00,47.80,18.60,61.26,39.90,42.70,139.30,26.70,39.30,10.80,258.00,217.70,22.80,79.10,361.50,56.10,32.40,286.42,56.19,291.71,66.10,25.00,22.20,100.70,453.39,176.46,107.12,9.09,18.70,54.30,43.40,54.00,43.10,147.00,66.16,313.70,116.17,62.80,203.73,29.80,196.70,649.20,24.80,79.13,236.60,32.62,160.50,356.96,173.53,119.90,40.20,23.30,71.40,51.60,44.10,240.01,24.50,88.20,51.00,580.30,55.44,33.50,15.20,25.04,12.00,1157.37,61.60,45.25,140.65,241.90,43.80,237.70,80.54,31.55,506.24,294.30,67.60,107.40,176.90,480.76,199.60,1891.85,148.78,322.10,796.20,68.80,105.72,128.70,99.80,118.76,96.00,182.32,166.84,112.00,404.70,11.84,5.92,35.70,26.40,45.93,29.90,102.81,22.63,303.90,124.09,86.29,41.80,62.80,173.42,144.41,669.81,132.90,192.06,40.67,153.29,24.40,34.03,24.80,30.60,1976.01,48.10,64.37,123.77,30.50,47.60,454.21,141.40,20.70,35.85,386.80,19.70,41.72,225.63,170.39,211.16,63.90,99.30,82.80,95.23,72.08,28.38,140.20,123.79,28.80,74.48,119.60,107.96,19.30,86.18,239.44,329.13,134.44,140.64,25.10,166.68,207.25,108.20,152.10,18.00,224.30,122.80,177.55,48.70,112.40,26.10,160.19,42.30,199.08,14.00,12.00,190.80,234.80,102.00,13.50,29.60,35.60,2172.78,35.30,15.10,40.80,15.48,106.50,12.80,86.60,12.80,11.80,52.93,248.90,146.40,80.10,272.09,29.20,191.20,421.70,18.00,201.00,55.90,54.29,235.10,96.47,333.29,69.30,122.47,162.99,99.76,275.50,190.89,15.48,20.38,53.50,176.80,203.70,307.98,290.08,9.90,51.52,135.20,12.00,116.10,87.84,62.00,71.40,136.00,27.80,17.60,81.20,115.63,182.10,13.00,114.35,29.10,43.83,16.30,130.56,183.80,94.70,25.70,268.60,81.90,46.60,40.69,196.88,55.10,112.70,68.49,271.17,16.84,86.27,146.76,11.50,14.80,77.50,81.36,65.53,178.64,144.87,135.20,63.11,162.70,47.45,260.20,125.97,27.70,92.20,89.00,145.77,150.58,98.02,16.90,733.70,111.39,372.00,92.40,136.60,132.35,125.04,175.39,91.20,76.10,36.38,665.63,28.40,301.85,124.70,18.00,38.50,103.10,13.80,78.90,65.61,12.80,1330.60,153.16,116.33,314.20,39.10,119.97,108.30,442.04,205.15,59.30,42.50,131.80,435.49,76.50,73.46,329.74,330.00,76.48,70.30,44.20,239.00,18.00,153.10,115.80,113.22,71.10,45.40,267.65,199.00,45.40,202.20,137.70,29.60,347.81,118.24,258.00,174.33,88.60,291.90,148.25,218.38,507.93,195.56,255.14,258.21,1004.00,152.16,12.80,317.00,65.20,411.90,64.40,33.00)
			.parallelStream()
			.map(p -> Integer.valueOf(String.valueOf(p).substring(0,1)))
			.collect(Collectors.groupingBy(p -> p,Collectors.counting()));
		
		DecimalFormat df = new DecimalFormat("#.0");
		result.forEach((k,v) -> {
			String pecent = String.format("%d => %s%%", k,df.format(v / 2000.0 * 100));
			System.out.println(pecent);
		});
	}
	
	private static void testItearator(){
		Stream.iterate(new int[]{0,1}, x -> new int[]{x[1],x[0] + x[1]}).map(x -> x[1]).limit(100).forEach(System.out::println);
	}
	
	private static void testGenerate(){
		Stream.generate(Math::random).forEach(System.out::println);
	}
	
	private static void testStream(){
		List<Integer> ages = Arrays.asList(67,21,45,56,10,20,51,55,52,53);
		Integer sum = ages.parallelStream()
				.map(Chinese::new)
//				.collect(Collectors.toList())
//				.stream()
				.filter((p) ->{
					System.out.println("filter : " + p.getAge());
					return p.getAge() > 50;
				})
//				.sorted(Comparator.comparing(Chinese::getAge).reversed())
				.map((p) -> {
					System.out.println("map : " + p.getAge());
					return p.getAge();
				})
				.sorted(Comparator.comparing(Integer::intValue).reversed())
				.limit(3)
				.collect(Collectors.toList())
				.stream()
				.filter(p -> p % 2 != 0)
				.reduce(0,Integer::sum);
//				.forEach(System.out::println);
		System.out.println(sum);
	}
}


